import { ObjectPool } from "../ObjectPool/ObjectPool";
import { CoroutineLockComponent } from "./CoroutineLockComponent";
import { CoroutineLockType } from "./CoroutineLockType";

export class CoroutineLock {

    private type: number;
    private key: number;
    private level: number;

    public static Create(type: number, key: number, level: number): CoroutineLock {
        let coroutineLock = ObjectPool.Instance.Fetch(CoroutineLock);
        coroutineLock.type = type;
        coroutineLock.key = key;
        coroutineLock.level = level;
        return coroutineLock;
    }

    public Dispose() {
        CoroutineLockComponent.Instance.RunNextCoroutine(this.type, this.key, this.level + 1);

        this.type = CoroutineLockType.None;
        this.key = 0;
        this.level = 0;

        ObjectPool.Instance.Recycle(this);
    }

}